﻿using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LiMinCRMPlugin
{
    /// <summary>
    /// 类名或功能模块简述
    /// </summary>
    /// <remarks>
    /// 功能：描述类或者模块的功能，多个功能要用编号分别罗列。
    /// 创建人：梦儿样
    /// 创建日期：2024/5/29 10:36:24
    /// 修改信息（1）：梦儿样，2024/5/29 10:36:24，修改内容
    /// </remarks>
    /// 
    [Description("应收单保存前自动赋值到期日")]
    [HotUpdate]
    public class ReceivableForm : AbstractBillPlugIn
    {

        public override void AfterSave(AfterSaveEventArgs e)
        {
            base.AfterSave(e);

        }
        public override void BeforeSave(BeforeSaveEventArgs e)
        {
            base.BeforeSave(e);
   

            var value = (DynamicObject)this.Model.GetValue("F_QLTK_PaymentMethod");
            if (value != null)
            {
                string fkfs = value["ID"].ToString();//付款方式
                string sql = string.Format(@"select * from QLTK_t_PaymentMethodDiy where fid='" + fkfs + "'");
                DataTable sql_toStirng = DBUtils.ExecuteDataSet(this.Context, sql).Tables[0];
                if (sql_toStirng != null && sql_toStirng.Rows.Count > 0)
                {
                    if (this.View.Model.GetValue("FSetAccountType") != null && this.View.Model.GetValue("F_QLTK_ExportDate") != null)
                    {
                        string FSetAccountType = this.View.Model.GetValue("FSetAccountType").ToString();//立账类型
                        DateTime ExportDate = Convert.ToDateTime(this.View.Model.GetValue("F_QLTK_ExportDate"));//出口日期
                        if (FSetAccountType == "3")
                        {
                            int days = Convert.ToInt32(sql_toStirng.Rows[0]["F_QLTK_PaymentDays"]);
                            DateTime dateTime = ExportDate.AddDays(days);

                            this.View.Model.SetValue("FENDDATE_H", dateTime.ToString());

                        }

                    }

                }
            }

        }
    }
}
